﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using ShevaEngine.Core.Interfaces;
using Microsoft.Xna.Framework.Input;

namespace ShevaEngine.Core.Modules.Input
{
    /// <summary>
    /// Sprava vstupu.
    /// </summary>
    public class InputManager : IUpdateAble
    {
        /// <summary>Singleton.</summary>
        public static readonly InputManager Instance = new InputManager();

        /// <summary>Keyboard</summary>
        public ShevaKeyboard Keyboard { get; private set; }
        /// <summary>Mouse</summary>
        public ShevaMouse Mouse { get; private set; }
        /// <summary>Gamepads.</summary>
        public ShevaGamepad[] Gamepads { get; private set; }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="eCore"></param>
        public InputManager()
        {
            this.Keyboard = new ShevaKeyboard();
            this.Mouse = new ShevaMouse();
            this.Gamepads = new ShevaGamepad[4];

            for (int i = 0; i < this.Gamepads.Length; i++)
                this.Gamepads[i] = new ShevaGamepad((PlayerIndex)i);
        }

        /// <summary>
        /// Pretizena metoda Update().
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            this.Keyboard.Update(gameTime);
            this.Mouse.Update(gameTime);
            
            for (int i = 3; i >= 0; i--)
                this.Gamepads[i].Update(gameTime);
        }
    }
}
